function validateinput(){
	var inputRetVal = true;
	var username=document.forms["login_input"]["loginusername"].value;
	var password=document.forms["login_input"]["loginpassword"].value;
	if (username==null || username==""){
	  document.getElementById('loginusernameillegal').innerHTML='Enter Username!';
	  inputRetVal = false;
	}
	else{
		document.getElementById('loginusernameillegal').innerHTML='';
	}
	if (password==null || password==""){
	  document.getElementById('loginpasswordillegal').innerHTML='Enter Password!';
	  inputRetVal = false;
	}
	else{
		document.getElementById('loginpasswordillegal').innerHTML='';
	}
	return inputRetVal;
}

var retVal;

function checkIfEmpty(value,object){
	var str = new String(value);
	var element = new String(object);
	if (str==null || str==""){
		  document.getElementById(element + 'illegal').innerHTML='Enter '+element+'!';
		  retVal = false;
	}
	else{
			document.getElementById(element + 'illegal').innerHTML='';
	}
}
function validateinputregister(){
	retVal = true;
	var username=document.forms["register_input"]["username"].value;
	var password=document.forms["register_input"]["password"].value;
	var repassword=document.forms["register_input"]["repassword"].value;
	var firstname=document.forms["register_input"]["firstname"].value;
	var lastname=document.forms["register_input"]["lastname"].value;
	var phonepre=document.forms["register_input"]["phonepre"].value;
	var phonesuf=document.forms["register_input"]["phonesuf"].value;
	var address=document.forms["register_input"]["address"].value;
	var authenticationcode=document.forms["register_input"]["authenticationcode"].value;
	checkIfEmpty(username,'username');
	checkIfEmpty(password,'password');
	checkIfEmpty(repassword,'repassword');
	if (password!=repassword){
		document.getElementById('repasswordillegal').innerHTML='Password and retype doesn\'t match!';
		retVal = false;
	}
	checkIfEmpty(firstname,'firstname');
	checkIfEmpty(lastname,'lastname');
	checkIfEmpty(phonepre,'phone');
	
	if ( retVal==true ){
		checkIfEmpty(phonesuf,'phone');
	}
	if ( retVal==true ){
		if (isNumber(phonesuf)){
			isNumber(phonepre);	
		}
	}
	if (document.getElementById('admin').checked == true){
		checkIfEmpty(authenticationcode,'authenticationcode');
	}
	return retVal;
}
function uncheckit(){
	document.getElementById('admin').checked = false;
}
function changeTextVisibilty() {
	if (document.getElementById('admin').checked == false){
		document.getElementById('hiddenArea').style.display = 'none';
	}
	else{
		document.getElementById('hiddenArea').style.display = 'table-row';
	}
}
function isNumber(n) {
	  if ( (!isNaN(parseFloat(n)) && isFinite(n)) == false){
		  document.getElementById('phoneillegal').innerHTML='Only digits allowed!';
		  retVal = false;
		  return false;
	  }
	  return true;
}
